<%--
  @author Duminda Dharmakeerthi
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script src="${pageContext.request.contextPath}/js/printer.js" type="text/javascript"></script>
<%--<link rel="stylesheet" href="${pageContext.request.contextPath}/css/printDetailForm.css" media="print"/>--%>

<script type="text/javascript">
    $(function() {
        initData();
        printReportHeader();
        $('.close').bind('click', function() {
            initData();
            printReportHeader();
        });
        $('select#gnDivisionId').bind('change', function(evt1) {
            initData();
            printReportHeader();
        });
    });

    function initData() {
        var id = $('select#gnDivisionId').attr('value');
        var mode = "byGNDivision";
        var type = "init";
        $.getJSON('${pageContext.request.contextPath}/common/LandLookupService', {id:id, mode:mode, type:type}, function(data) {
            loadLandList(data.landList);
        });
    }

    function loadLandList(landInfo) {
        var opt = '';
        opt += '<thead>' +
                '<tr class="table-header">' +
                '<th class="left-align">' + $('#ref').val() + '</th>' +
                '<th class="left-align">' + $('#vil').val() + '</th>' +
                '<th class="left-align">' + $('#lname').val() + '</th>' +
                '<th class="left-align">' + $('#plan').val() + '</th>' +
                '<th class="left-align">' + $('#lot').val() + '</th>' +
                '<th class="left-align">' + $('#ext_hec').val() + '</th>' +
                '<th class="left-align">' + $('#schedule_date').val() + '</th>' +
                '<th class="left-align">' + $('#alienation_type').val() + '</th>' +
                '<th class="left-align">' + $('#alienation_number').val() + '</th>' +
                '</tr>' +
                '</thead>';
        opt += '<tbody>';
        if (landInfo.length > 0) {
            for (var i = 0; i < landInfo.length; i++) {
                var reference = (landInfo[i].referenceNumber > 0) ? landInfo[i].referenceNumber : landInfo[i].id;
                var extent = (landInfo[i].kmlLandArea > 0) ? landInfo[i].kmlLandArea : landInfo[i].landExtent;
                //extent=roundNumber(extent, 4);
                extent = getHect(extent);
                var scheduleDate = (landInfo[i].scheduleDate != null) ? landInfo[i].scheduleDate : '';
                var alienationNumber = (landInfo[i].alienationNumber != 0) ? landInfo[i].alienationNumber : '';
                opt += '<tr>' +
                        '<td class="left-align">' + reference + '</td>' +
                        '<td class="left-align">' + landInfo[i].village + '</td>' +
                        '<td class="left-align">' + landInfo[i].nameOfTheLand + '</td>' +
                        '<td class="left-align">' + landInfo[i].planNumber + '</td>' +
                        '<td class="left-align">' + landInfo[i].lotNumber + '</td>' +
                        '<td class="left-align">' + extent + '</td>' +
                        '<td class="left-align">' + scheduleDate + '</td>' +
                        '<td class="left-align">' + landInfo[i].alienationMethod + '</td>' +
                        '<td class="left-align">' + alienationNumber + '</td>' +
                        '</tr>';
            }
            $('.print-btn').val($('#print').val());
            $('.print-btn').show();
            $('#report-header').show();
        }
        opt += '</tbody>';
        $('.land-table').html(opt);
    }
    $(document).ready(function() {
        $('.print-btn').hide();
        $('#report-header').hide();
        $('.print-btn').printPreview({

        });
    });

    function printReportHeader() {
        $('#district').val($('#districtId').val());
        $('#ds-name').val($('#dsDivisionId').val());
        var selectedGN = document.getElementById('gnDivisionId').selectedIndex;
        var gnDivision = document.getElementById('gnDivisionId').options[selectedGN].text;
        $('#gn-name').val(gnDivision);
    }

    function roundNumber(number, decimals) { // Arguments: number to round, number of decimal places
        var newnumber = new Number(number + '').toFixed(parseInt(decimals));
        return parseFloat(newnumber);
    }

    function getHect(pershes) {
        var he = 0,ac = 0,ro = 0,pe = 0,temp = 0;
        var cont = 2.47105381467;
        ac = 0;
        ro = 0;
        pe = pershes;

        ac = parseFloat(ac);
        ro = parseFloat(ro);
        pe = parseFloat(pe);

        ro = parseFloat(ro + pe / 40);
        ac = parseFloat(ac + ro / 4);
        he = parseFloat(ac / cont).toFixed(4);
        if (he == 0.0000) {
            he = 0;
        }
        return he;
    }


</script>

<div id="land-registration-module-home-title" class="module-home-title">
    <s:a href="reportModule.do">
        <span><img src="${pageContext.request.contextPath}/images/print.png" alt="Print">
            <s:label value="%{getText('reports.label')}"/></span>
    </s:a>
    <span class="module-title-breaker"> > </span>
    <s:a href="initFormList.do">
        <span><img src="${pageContext.request.contextPath}/images/list.png" alt="Initial Land Report">
            <s:label value="%{getText('init_land_report_by_gn.label')}"/></span>
    </s:a>
</div>

<s:include value="../printCaller.jsp"/>
<div id="printDivId">

    <div id="init-land-report-list">
        <div class="page-title center-align">
            <h2><s:label value="%{getText('init_land_report_by_gn.label')}"/></h2>
        </div>
        <table class="width-500-px margin-10-auto" id="filter-lists">
            <tr>
                <td><s:label value="%{getText('district.label')}"/></td>
                <td><s:textfield id="districtId" name="districtName" cssClass="width-200-px" disabled="true"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('ds_division.label')}"/></td>
                <td><s:textfield id="dsDivisionId" name="dsDivisionName" cssClass="width-200-px" disabled="true"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('gn_division.label')}"/></td>
                <td><s:select id="gnDivisionId" name="gnDivisionId" list="gnDivisionList" headerKey="0"
                              headerValue="%{getText('all.label')}" cssClass="width-200-px"/></td>
            </tr>
        </table>
        <div id="report-header">
            <table class="width-100 margin-10-auto">
                <tr>
                    <td><s:label value="%{getText('district.label')}"/> : <s:textfield id="district"
                                                                                       cssStyle="border:none; background: none; color: #000;"
                                                                                       disabled="true"/></td>
                </tr>
                <tr>
                    <td><s:label value="%{getText('ds_division.label')}"/> : <s:textfield id="ds-name"
                                                                                          cssStyle="border:none; background: none; color: #000;"
                                                                                          disabled="true"/></td>
                </tr>
                <tr>
                    <td><s:label value="%{getText('gn_division.label')}"/> : <s:textfield id="gn-name"
                                                                                          cssStyle="border:none; background: none; color: #000;"
                                                                                          disabled="true"/></td>
                </tr>
            </table>
        </div>


        <div id="land-list">
            <%--<div id="printbtn" class="form-button-div right-align">
                &lt;%&ndash;<input type="button" value="Print" id="print"  class="print-btn">&ndash;%&gt;
                <input class="print-btn" type="button" value="Print" onclick="printInitialPage();">
            </div>--%>

            <table class="width-100 margin-10-auto table land-table" id="land-report-by-gn" border="1" cellpadding="0"
                   cellspacing="0">

            </table>
            <%--<div class="right-align print-div">
                <input class="print-btn" type="button"/>
            </div>--%>
        </div>

    </div>
</div>

<%-- Localization text for java script generated text --%>
<s:hidden id="ref" value="%{getText('reference_no.label')}"/>
<s:hidden id="lname" value="%{getText('name_of_the_land.label')}"/>
<s:hidden id="plan" value="%{getText('plan_no.label')}"/>
<s:hidden id="lot" value="%{getText('lot_no.label')}"/>
<s:hidden id="vil" value="%{getText('village.label')}"/>
<s:hidden id="ext_pec" value="%{getText('extent_perches.label')}"/>
<s:hidden id="ext_hec" value="%{getText('extent_hectare.label')}"/>
<s:hidden id="schedule_date" value="%{getText('schedule_date.label')}"/>
<s:hidden id="alienation_type" value="%{getText('alienation_type')}"/>
<s:hidden id="alienation_number" value="%{getText('alienation_number')}"/>
<s:hidden id="undefined" value="%{getText('undefined.label')}"/>

<%-- Localization text for data tables --%>
<s:hidden id="display" value="%{getText('display.label')}"/>
<s:hidden id="records" value="%{getText('records.label')}"/>
<s:hidden id="search" value="%{getText('search.label')}"/>
<s:hidden id="no-record" value="%{getText('no_record.label')}"/>
<s:hidden id="showing" value="%{getText('showing.label')}"/>
<s:hidden id="to" value="%{getText('to.label')}"/>
<s:hidden id="of" value="%{getText('of.label')}"/>
<s:hidden id="entries" value="%{getText('entries.label')}"/>
<s:hidden id="first" value="%{getText('first.label')}"/>
<s:hidden id="last" value="%{getText('last.label')}"/>
<s:hidden id="next" value="%{getText('next.label')}"/>
<s:hidden id="previous" value="%{getText('previous.label')}"/>

<%-- Localization for report by GN Division--%>
<s:hidden id="report-title" value="%{getText('land_list_by_gn_division.label')}"/>
<s:hidden id="print" value="%{getText('print.label')}"/> 